<template>
    <div class="component-input-box" :data-value="value">
        <div class="label" :style="{width: labelWidth ? (labelWidth / 10) + 'rem' : '6rem'}">
            <span v-for="text in label">{{text}}</span>
        </div>
        <template v-if="type == 'select'">
            <div class="input-box app-right-icon" :class="{'text-gray': !value}" @click="$emit('onclick')">{{value || placeholder}}</div>
        </template>
        <template v-else-if="type == 'date'">
            <div class="input-box app-right-icon-date" :class="{'text-gray': !value}" @click="$emit('onclick')">{{value || placeholder}}</div>
        </template>
        <input v-else="" class="input-box" :placeholder="placeholder" v-model="val" @input="$emit('input', $event.target.value);">
    </div>
</template>

<style lang="less" scoped>

    @import '../style/variable';

    .component-input-box{
        display: flex;
        height: 4.5rem;
        align-items: center;
        font-size: 1.6rem;
        padding: 0 1.5rem;

        &:not(:last-child){
            border-bottom: 1px solid @color-line-gray;
        }

        .label{
            display: flex;
            justify-content: space-between;
            color: @color-text-gray;

        }
        .input-box{
            flex: 1;
            font-size: 1.6rem;
            margin-left: 2rem;
        }
    }

</style>

<script>
    export default {
        data(){
            return {
                val: this.value,
                showSelect: false
            }
        },
        props: ['value', 'placeholder', 'label', 'label-width', 'type'],
        beforeUpdate(){
            this.val = this.value;
        }
    }
</script>